package cn.campus.converter;

import cn.campus.pojo.article.dto.ArticleDTO;
import cn.campus.pojo.article.po.Article;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * Created by linyanbin on 2018/9/24.
 */
public class ArticleDTOToArticleConverter {

    /**
     * 将ArticleDTO对象转成Article对象
     * @param articleDTO
     * @return
     */
    public static Article convert(ArticleDTO articleDTO){
        Article article = null;
        if (articleDTO != null) {
            article = new Article();
            BeanUtils.copyProperties(articleDTO, article);
        }
        return article;
    }

    /**
     * 将ArticleDTO对象列表转成Article列表
     * @param articleDTOList
     * @return
     */
    public static List<Article> convert(List<ArticleDTO> articleDTOList){
        if (Objects.isNull(articleDTOList) || articleDTOList.size() == 0) {
            return null;
        }
        return articleDTOList.stream().map(ArticleDTOToArticleConverter::convert).collect(Collectors.toList());
    }
}
